package cn.catsdad.page;

import cn.catsdad.base.page.PageParam;
import cn.catsdad.util.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 常量管理查询参数
 *
 * @author xuyonglong
 * @version V1.0 2023/4/24
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class DictParam extends PageParam {

    private Map<String, Object> paramMap = new HashMap<>();

    /**
     * 关键字查询，常量名称、常量编码
     */
    private String key;

    /**
     * 状态查询
     * @see cn.catsdad.constant.enumConstant.GenericStatus
     */
    private int status;

    @Override
    public Map<String, Object> getParamMap() {
        return this.paramMap;
    }

    @Override
    public String getCondition() {
        StringBuilder condition = new StringBuilder(" and d.isDeleted = 0");
        if (StringUtil.isNotEmpty(this.key)) {
            condition.append(" and (d.name like :key or d.code like :key )");
            this.paramMap.put("key", likeQuery(this.key));
        }
        if (this.status != 0) {
            condition.append(" and d.status = :status ");
            this.paramMap.put("status", this.status);
        }

        return condition.toString();
    }
}
